Skip to content

fix(next): silence OpenTelemetry "Critical dependency" warnings in build#555

Open
Vadman97 wants to merge 1 commit into
mainfrom
vkorolik/next-otel-warnings
Open

fix(next): silence OpenTelemetry "Critical dependency" warnings in build#555
Vadman97 wants to merge 1 commit into
mainfrom
vkorolik/next-otel-warnings

Conversation

@Vadman97
Copy link
Copy Markdown
Contributor

@Vadman97 Vadman97 commented May 13, 2026

Summary

Backend Next.js apps using @highlight-run/next/server (typically via instrumentation.ts) currently emit a wall of Critical dependency: the request of a dependency is an expression warnings during next build. The root cause is that @highlight-run/node pulls @opentelemetry/instrumentation (via @prisma/instrumentation) and uses require-in-the-middle / import-in-the-middle, which webpack cannot statically analyze.

This PR teaches withHighlightConfig to suppress these warnings out of the box so customers don't need to know about the underlying webpack quirk:

  • Primary fix: merge an OTel/RITM/ITM package list into Next 15's serverExternalPackages, so Next defers to Node's runtime require instead of bundling them. Preserves any existing user-provided entries and deduplicates.
  • Defense-in-depth: add ignoreWarnings filters to the server webpack config covering both node_modules/... (typical install) and highlight-node/dist/... (workspace / hoisted) paths, scoped to the exact warning message.

Verified against the e2e/nextjs example: the Critical dependency warnings that were present before this change are gone after it. Existing with-highlight-config unit tests still pass; added four new tests covering serverExternalPackages merge/dedup and the server-only ignoreWarnings behavior.

Test plan

  • yarn workspace @highlight-run/next test — 15/15 pass
  • yarn turbo run lint --filter=@highlight-run/next — clean
  • yarn format-check — clean
  • e2e/nextjs next build no longer emits Critical dependency warnings (pre-existing unrelated type error in the example is untouched)

🤖 Generated with Claude Code


Note

Medium Risk
Changes Next.js server build configuration by externalizing OpenTelemetry-related packages and suppressing specific webpack warnings, which could affect server bundling behavior in some deployments.

Overview
Reduces noisy next build output for apps using Highlight + OpenTelemetry by automatically treating several OTel/Prisma and *-in-the-middle modules as server externals via serverExternalPackages, while preserving user entries and deduplicating.

Adds a server-only webpack ignoreWarnings filter for the known OpenTelemetry “Critical dependency” warning (including hoisted/workspace layouts), and extends unit tests to cover the externals merge/dedup behavior and the server-vs-client warning suppression.

Reviewed by Cursor Bugbot for commit 617f721. Bugbot is set up for automated code reviews on this repo. Configure here.

`@highlight-run/node` pulls `@opentelemetry/instrumentation` and uses
`require-in-the-middle`, which webpack cannot statically analyze. Next.js
emits a wall of "Critical dependency: the request of a dependency is an
expression" warnings during `next build` in every customer app that uses
`registerHighlight` from `instrumentation.ts`.

`withHighlightConfig` now (1) adds the OpenTelemetry / RITM / ITM packages
to `serverExternalPackages` so Next defers to Node's runtime require, and
(2) registers `ignoreWarnings` on the server webpack config as
defense-in-depth for workspace and hoisted setups.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Vadman97 Vadman97 requested a review from a team as a code owner May 13, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants